
<!DOCTYPE HTML>
<html lang="zh-hans" >
    <head>
        <meta charset="UTF-8">
        <meta content="text/html; charset=utf-8" http-equiv="Content-Type">
        <title>项目结构和初始化 · GitBook</title>
        <meta http-equiv="X-UA-Compatible" content="IE=edge" />
        <meta name="description" content="">
        <meta name="generator" content="GitBook 3.2.3">
        
        
        
    
    <link rel="stylesheet" href="../../gitbook/style.css">

    
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-highlight/website.css">
                
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-search/search.css">
                
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-fontsettings/website.css">
                
            
        

    

    
        
    
        
    
        
    
        
    
        
    
        
    

        
    
    
    <meta name="HandheldFriendly" content="true"/>
    <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <link rel="apple-touch-icon-precomposed" sizes="152x152" href="../../gitbook/images/apple-touch-icon-precomposed-152.png">
    <link rel="shortcut icon" href="../../gitbook/images/favicon.ico" type="image/x-icon">

    
    <link rel="next" href="api.html" />
    
    

    </head>
    <body>
        
<div class="book">
    <div class="book-summary">
        
            
<div id="book-search-input" role="search">
    <input type="text" placeholder="输入并搜索" />
</div>

            
                <nav role="navigation">
                


<ul class="summary">
    
    

    

    
        
        
    
        <li class="chapter " data-level="1.1" data-path="../">
            
                <a href="../">
            
                    
                    概览
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2" >
            
                <span>
            
                    
                    快速入门
            
                </span>
            

            
            <ul class="articles">
                
    
        <li class="chapter active" data-level="1.2.1" data-path="project.html">
            
                <a href="project.html">
            
                    
                    项目结构和初始化
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.2" data-path="api.html">
            
                <a href="api.html">
            
                    
                    API
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.3" data-path="doc.html">
            
                <a href="doc.html">
            
                    
                    生成 API 文档
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.4" data-path="client.html">
            
                <a href="client.html">
            
                    
                    生成客户端
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.3" >
            
                <span>
            
                    
                    概念
            
                </span>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.3.1" data-path="../concepts/cp.html">
            
                <a href="../concepts/cp.html">
            
                    
                    Consumer && Producer
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.2" data-path="../concepts/operator.html">
            
                <a href="../concepts/operator.html">
            
                    
                    Operator
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.3" data-path="../concepts/filter.html">
            
                <a href="../concepts/filter.html">
            
                    
                    Filter
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.4" data-path="../concepts/prefab.html">
            
                <a href="../concepts/prefab.html">
            
                    
                    Prefab
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.5" data-path="../concepts/modifier.html">
            
                <a href="../concepts/modifier.html">
            
                    
                    Modifier
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.6" data-path="../concepts/middleware.html">
            
                <a href="../concepts/middleware.html">
            
                    
                    Middleware
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.7" data-path="../concepts/context.html">
            
                <a href="../concepts/context.html">
            
                    
                    Context
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.8" data-path="../concepts/source.html">
            
                <a href="../concepts/source.html">
            
                    
                    Parameter Generator
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.9" data-path="../concepts/destination.html">
            
                <a href="../concepts/destination.html">
            
                    
                    Destination Handler
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.10" data-path="../concepts/error.html">
            
                <a href="../concepts/error.html">
            
                    
                    错误包
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.11" data-path="../concepts/method.html">
            
                <a href="../concepts/method.html">
            
                    
                    方法包
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.12" data-path="../concepts/configurer.html">
            
                <a href="../concepts/configurer.html">
            
                    
                    配置器机制
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.13" data-path="../concepts/plugin.html">
            
                <a href="../concepts/plugin.html">
            
                    
                    插件机制
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.14" data-path="../concepts/clients.html">
            
                <a href="../concepts/clients.html">
            
                    
                    多客户端整合
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.4" >
            
                <span>
            
                    
                    插件
            
                </span>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.4.1" data-path="../plugins/logger.html">
            
                <a href="../plugins/logger.html">
            
                    
                    系统日志插件
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.2" data-path="../plugins/reqlog.html">
            
                <a href="../plugins/reqlog.html">
            
                    
                    请求日志插件
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.3" data-path="../plugins/metrics.html">
            
                <a href="../plugins/metrics.html">
            
                    
                    监控指标插件
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.4" data-path="../plugins/tracing.html">
            
                <a href="../plugins/tracing.html">
            
                    
                    请求追踪插件
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.5" data-path="../plugins/profiling.html">
            
                <a href="../plugins/profiling.html">
            
                    
                    性能分析插件
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.6" data-path="../plugins/version.html">
            
                <a href="../plugins/version.html">
            
                    
                    版本信息插件
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.7" data-path="../plugins/healthcheck.html">
            
                <a href="../plugins/healthcheck.html">
            
                    
                    健康检查插件
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.5" >
            
                <span>
            
                    
                    框架开发者指南
            
                </span>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.5.1" data-path="../topics/start.html">
            
                <a href="../topics/start.html">
            
                    
                    准备工作
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.2" data-path="../topics/log.html">
            
                <a href="../topics/log.html">
            
                    
                    log
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.3" data-path="../topics/errors.html">
            
                <a href="../topics/errors.html">
            
                    
                    errors
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.4" data-path="../topics/definition.html">
            
                <a href="../topics/definition.html">
            
                    
                    definition
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.5" data-path="../topics/method.html">
            
                <a href="../topics/method.html">
            
                    
                    definition/method
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.6" data-path="../topics/converter.html">
            
                <a href="../topics/converter.html">
            
                    
                    operators/converter
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.7" data-path="../topics/validator.html">
            
                <a href="../topics/validator.html">
            
                    
                    operators/validator
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.8" data-path="../topics/router.html">
            
                <a href="../topics/router.html">
            
                    
                    service/router
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.9" data-path="../topics/service.html">
            
                <a href="../topics/service.html">
            
                    
                    service
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.10" data-path="../topics/nirvana.html">
            
                <a href="../topics/nirvana.html">
            
                    
                    nirvana
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.11" data-path="../topics/config.html">
            
                <a href="../topics/config.html">
            
                    
                    config
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.12" data-path="../topics/rest.html">
            
                <a href="../topics/rest.html">
            
                    
                    rest
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.13" data-path="../topics/utils.html">
            
                <a href="../topics/utils.html">
            
                    
                    utils
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.14" data-path="../topics/command.html">
            
                <a href="../topics/command.html">
            
                    
                    cmd/nirvana
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    

    

    <li class="divider"></li>

    <li>
        <a href="https://www.gitbook.com" target="blank" class="gitbook-link">
            本书使用 GitBook 发布
        </a>
    </li>
</ul>


                </nav>
            
        
    </div>

    <div class="book-body">
        
            <div class="body-inner">
                
                    

<div class="book-header" role="navigation">
    

    <!-- Title -->
    <h1>
        <i class="fa fa-circle-o-notch fa-spin"></i>
        <a href=".." >项目结构和初始化</a>
    </h1>
</div>




                    <div class="page-wrapper" tabindex="-1" role="main">
                        <div class="page-inner">
                            
<div id="book-search-results">
    <div class="search-noresults">
    
                                <section class="normal markdown-section">
                                
                                <h1 id="&#x9879;&#x76EE;&#x7ED3;&#x6784;&#x548C;&#x521D;&#x59CB;&#x5316;">&#x9879;&#x76EE;&#x7ED3;&#x6784;&#x548C;&#x521D;&#x59CB;&#x5316;</h1>
<h2 id="&#x521B;&#x5EFA;&#x9879;&#x76EE;">&#x521B;&#x5EFA;&#x9879;&#x76EE;</h2>
<p>Nirvana &#x521B;&#x5EFA;&#x9879;&#x76EE;&#x975E;&#x5E38;&#x7B80;&#x5355;&#xFF0C;&#x4E0D;&#x8FC7;&#x5728;&#x521B;&#x5EFA;&#x9879;&#x76EE;&#x4E4B;&#x524D;&#xFF0C;&#x9996;&#x5148;&#x9700;&#x8981;&#x4E0B;&#x8F7D;&#x5B89;&#x88C5; Nirvana &#x7684;&#x547D;&#x4EE4;&#x884C;&#x5DE5;&#x5177;&#xFF1A;</p>
<pre><code>$ go get -u github.com/caicloud/nirvana/cmd/nirvana
</code></pre><p>&#x7136;&#x540E;&#x5C31;&#x53EF;&#x4EE5;&#x76F4;&#x63A5;&#x4F7F;&#x7528;&#x547D;&#x4EE4;&#x521B;&#x5EFA;&#x9879;&#x76EE;&#xFF08;&#x8BF7;&#x786E;&#x4FDD; <code>$GOPATH/bin</code> &#x5728; <code>$PATH</code> &#x4E2D;&#xFF09;&#xFF1A;</p>
<pre><code>$ cd $GOPATH/src/
$ nirvana init ./myproject
$ cd ./myproject
</code></pre><p>&#x6B64;&#x65F6;&#x5728; <code>$GOPATH/src/myproject</code> &#x4F1A;&#x751F;&#x6210;&#x4E00;&#x4E2A;&#x5B8C;&#x6574;&#x7684; Nirvana &#x9879;&#x76EE;&#x3002;&#x9879;&#x76EE;&#x7ED3;&#x6784;&#x5982;&#x4E0B;&#xFF1A;</p>
<pre><code>.                                   #
&#x251C;&#x2500;&#x2500; .golangci.yml                   #
&#x251C;&#x2500;&#x2500; go.mod                          #
&#x251C;&#x2500;&#x2500; Makefile                        #
&#x251C;&#x2500;&#x2500; OWNERS                          #
&#x251C;&#x2500;&#x2500; README.md                       #
&#x251C;&#x2500;&#x2500; apis                            # Store apidocs (swagger json)
&#x251C;&#x2500;&#x2500; bin                             # Store the compiled binary
&#x251C;&#x2500;&#x2500; build                           # Store Dockerfile
&#x2502;   &#x2514;&#x2500;&#x2500; demo-admin                  #
&#x2502;       &#x2514;&#x2500;&#x2500; Dockerfile              #
&#x251C;&#x2500;&#x2500; cmd                             # Store startup commands for project
&#x2502;   &#x2514;&#x2500;&#x2500; demo-admin                  #
&#x2502;       &#x2514;&#x2500;&#x2500; main.go                 #
&#x251C;&#x2500;&#x2500; docs                            # Store docs
&#x2502;   &#x2514;&#x2500;&#x2500; README.md                   #
&#x251C;&#x2500;&#x2500; hack                            # Store scripts
&#x2502;   &#x251C;&#x2500;&#x2500; README.md                   #
&#x2502;   &#x251C;&#x2500;&#x2500; read_cpus_available.sh      # Script to read available cpus
&#x2502;   &#x2514;&#x2500;&#x2500; script.sh                   #
&#x251C;&#x2500;&#x2500; nirvana.yaml                    # File to describes your project
&#x251C;&#x2500;&#x2500; pkg                             # Store structures and converters required by API, distinguish by version
&#x2502;   &#x251C;&#x2500;&#x2500; apis                        #
&#x2502;   &#x2502;   &#x251C;&#x2500;&#x2500; descriptors.go          # Store API descriptions (routing and others), distinguish by version
&#x2502;   &#x2502;   &#x2514;&#x2500;&#x2500; v1                      #
&#x2502;   &#x2502;       &#x251C;&#x2500;&#x2500; converters          #
&#x2502;   &#x2502;       &#x2502;   &#x2514;&#x2500;&#x2500; converters.go   #
&#x2502;   &#x2502;       &#x251C;&#x2500;&#x2500; descriptors         #
&#x2502;   &#x2502;       &#x2502;   &#x251C;&#x2500;&#x2500; descriptors.go  #
&#x2502;   &#x2502;       &#x2502;   &#x2514;&#x2500;&#x2500; message.go      # Store API definition of message
&#x2502;   &#x2502;       &#x2514;&#x2500;&#x2500; types.go            #
&#x2502;   &#x251C;&#x2500;&#x2500; filters                     # Store HTTP Request filter
&#x2502;   &#x2502;   &#x2514;&#x2500;&#x2500; filter.go               #
&#x2502;   &#x251C;&#x2500;&#x2500; handlers                    # Store the logical processing required by APIs
&#x2502;   &#x2502;   &#x2514;&#x2500;&#x2500; message.go              #
&#x2502;   &#x251C;&#x2500;&#x2500; middlewares                 # Store middlewares
&#x2502;   &#x2502;   &#x2514;&#x2500;&#x2500; middlewares.go          #
&#x2502;   &#x251C;&#x2500;&#x2500; modifiers                   # Store definition modifiers
&#x2502;   &#x2502;   &#x2514;&#x2500;&#x2500; modifiers.go            #
&#x2502;   &#x2514;&#x2500;&#x2500; version                     # Store version information of project
&#x2502;       &#x2514;&#x2500;&#x2500; version.go              #
&#x251C;&#x2500;&#x2500; test                            # Store all tests (except unit tests), e.g. integration, e2e tests.
&#x2502;   &#x2514;&#x2500;&#x2500; test_make.sh                #
&#x2514;&#x2500;&#x2500; vendor                          #
</code></pre><p>&#x8FD9;&#x4E2A;&#x9879;&#x76EE;&#x4E2D;&#x5305;&#x542B;&#x4E86;&#x7F16;&#x8BD1;&#x548C;&#x6784;&#x5EFA;&#x5BB9;&#x5668;&#x7684;&#x57FA;&#x672C;&#x5DE5;&#x5177;&#xFF08;Makefile &#x548C; Dockefile&#xFF09;&#xFF0C;&#x8FD8;&#x6709; go mod &#x9700;&#x8981;&#x7684;&#x5305;&#x5B9A;&#x4E49;&#x6587;&#x4EF6; <code>go.mod</code>&#x3002;&#x901A;&#x8FC7;&#x5982;&#x4E0B;&#x547D;&#x4EE4;&#x5373;&#x53EF;&#x5B8C;&#x6210;&#x4F9D;&#x8D56;&#x5305;&#x7684;&#x5B89;&#x88C5;&#xFF1A;</p>
<pre><code>$ go mod tidy
$ go mod vendor # &#x5982;&#x679C;&#x9700;&#x8981; vendor &#x7684;&#x8BDD;
</code></pre><p>&#x5230;&#x8FD9;&#x91CC;&#x5C31;&#x5B8C;&#x6210;&#x4E86;&#x6574;&#x4E2A;&#x9879;&#x76EE;&#x7684;&#x521B;&#x5EFA;&#x548C;&#x4F9D;&#x8D56;&#x5B89;&#x88C5;&#x5DE5;&#x4F5C;&#xFF0C;&#x9ED8;&#x8BA4;&#x7684;&#x9879;&#x76EE;&#x7ED3;&#x6784;&#x4E2D;&#x81EA;&#x5E26;&#x4E86;&#x4E00;&#x4E2A; API &#x8303;&#x4F8B;&#xFF0C;&#x56E0;&#x6B64;&#x53EF;&#x4EE5;&#x76F4;&#x63A5;&#x8FD0;&#x884C;&#x67E5;&#x770B;&#x6548;&#x679C;&#x3002;</p>
<h2 id="&#x7F16;&#x8BD1;&#x8FD0;&#x884C;">&#x7F16;&#x8BD1;&#x8FD0;&#x884C;</h2>
<h3 id="&#x76F4;&#x63A5;&#x7F16;&#x8BD1;&#x8FD0;&#x884C;">&#x76F4;&#x63A5;&#x7F16;&#x8BD1;&#x8FD0;&#x884C;</h3>
<p>Nirvana &#x521B;&#x5EFA;&#x9879;&#x76EE;&#x65F6;&#x81EA;&#x52A8;&#x751F;&#x6210;&#x4E86; Makefile&#xFF0C;&#x53EA;&#x9700;&#x8981;&#x4F7F;&#x7528;&#x7B80;&#x5355;&#x7684; <code>make</code> &#x547D;&#x4EE4;&#x5C31;&#x53EF;&#x4EE5;&#x5B8C;&#x6210;&#x7F16;&#x8BD1;&#x5DE5;&#x4F5C;&#xFF1A;</p>
<pre><code>$ make build-local
</code></pre><p>&#x5728;&#x9879;&#x76EE;&#x7684; <code>bin</code> &#x76EE;&#x5F55;&#x4E2D;&#x5C31;&#x80FD;&#x770B;&#x5230;&#x7F16;&#x8BD1;&#x540E;&#x7684;&#x4E8C;&#x8FDB;&#x5236;&#x6587;&#x4EF6;&#xFF0C;&#x76F4;&#x63A5;&#x8FD0;&#x884C;&#xFF1A;</p>
<pre><code>$ ./bin/myproject
</code></pre><p>&#x542F;&#x52A8;&#x65F6;&#x4F1A;&#x6253;&#x5370;&#x51FA; Nirvana &#x7684; Logo &#x4EE5;&#x53CA;&#x5F53;&#x524D;&#x9879;&#x76EE;&#x7684;&#x7248;&#x672C;&#x4FE1;&#x606F;&#x4EE5;&#x53CA;&#x76D1;&#x542C;&#x7684;&#x7AEF;&#x53E3;&#xFF0C;&#x9ED8;&#x8BA4;&#x7AEF;&#x53E3;&#x662F; 8080&#x3002;</p>
<p>&#x5728;&#x670D;&#x52A1;&#x542F;&#x52A8;&#x4E4B;&#x540E;&#xFF0C;&#x53EF;&#x4EE5;&#x901A;&#x8FC7;&#x6D4F;&#x89C8;&#x5668;&#x6216;&#x8005;&#x547D;&#x4EE4;&#x884C;&#x8BBF;&#x95EE; <code>http://localhost:8080/apis/v1/messages</code>&#xFF1A;</p>
<pre><code>$ curl http://localhost:8080/apis/v1/messages
</code></pre><p>&#x5C31;&#x80FD;&#x591F;&#x770B;&#x5230; API &#x7684;&#x8FD4;&#x56DE;&#x7ED3;&#x679C;&#x3002;</p>
<h3 id="&#x7F16;&#x8BD1;&#x5E76;&#x6253;&#x5305;&#x6210;-docker-&#x955C;&#x50CF;">&#x7F16;&#x8BD1;&#x5E76;&#x6253;&#x5305;&#x6210; Docker &#x955C;&#x50CF;</h3>
<p>&#x5728;&#x9700;&#x8981;&#x53D1;&#x5E03;&#x7684;&#x65F6;&#x5019;&#xFF0C;&#x901A;&#x5E38;&#x9700;&#x8981;&#x6253;&#x5305;&#x6210;&#x955C;&#x50CF;&#x7684;&#x5F62;&#x5F0F;&#xFF0C;&#x5728; Makefile &#x4E2D;&#x4E5F;&#x63D0;&#x4F9B;&#x4E86;&#x76F4;&#x63A5;&#x6253;&#x5305;&#x6210;&#x955C;&#x50CF;&#x7684;&#x547D;&#x4EE4;&#xFF1A;</p>
<pre><code>$ make container
</code></pre><p>&#x5C31;&#x4F1A;&#x81EA;&#x52A8;&#x5F00;&#x59CB;&#x5728;&#x5BB9;&#x5668;&#x5185;&#x7F16;&#x8BD1;&#x548C;&#x6253;&#x5305;&#x955C;&#x50CF;&#x3002;&#x4E0D;&#x8FC7;&#x8FD9;&#x4E2A;&#x8FC7;&#x7A0B;&#x4E2D;&#x9700;&#x8981; <code>golang</code> &#x548C; <code>debian:stretch</code> &#x8FD9;&#x4E24;&#x4E2A;&#x955C;&#x50CF;&#x3002;&#x5982;&#x679C;&#x672C;&#x5730;&#x6CA1;&#x6709;&#x8FD9;&#x4E24;&#x4E2A;&#x955C;&#x50CF;&#xFF0C;&#x6216;&#x8005;&#x5E0C;&#x671B;&#x4F7F;&#x7528;&#x5176;&#x4ED6;&#x955C;&#x50CF;&#x8FDB;&#x884C;&#x7F16;&#x8BD1;&#x548C;&#x6784;&#x5EFA;&#x5DE5;&#x4F5C;&#xFF0C;&#x8BF7;&#x4FEE;&#x6539; Makefile &#x548C; <code>./build/myproject/Dockerfile</code> &#x6216;&#x5728;&#x4F7F;&#x7528; init &#x751F;&#x6210;&#x9879;&#x76EE;&#x7684;&#x65F6;&#x5019;&#x4F7F;&#x7528; <code>--registry</code> &#x548C; <code>--base-registry</code> &#x6307;&#x5B9A;&#x955C;&#x50CF;&#x4ED3;&#x5E93;&#x7684;&#x5730;&#x5740;&#x3002;</p>
<p>&#x6253;&#x5305;&#x5B8C;&#x6210;&#x540E;&#xFF0C;&#x53EF;&#x4EE5;&#x901A;&#x8FC7; Docker &#x547D;&#x4EE4;&#x542F;&#x52A8;&#x5BB9;&#x5668;&#xFF0C;&#x7136;&#x540E;&#x8FDB;&#x884C;&#x8BBF;&#x95EE;&#xFF1A;</p>
<pre><code>$ docker run -p 8080:8080 myproject:v0.1.0
</code></pre><h2 id="nirvana-&#x9879;&#x76EE;&#x914D;&#x7F6E;">Nirvana &#x9879;&#x76EE;&#x914D;&#x7F6E;</h2>
<p>&#x6BCF;&#x4E2A; Nirvana &#x9879;&#x76EE;&#x90FD;&#x6709;&#x4E00;&#x4E2A; <code>nirvana.yaml</code> &#x914D;&#x7F6E;&#x6587;&#x4EF6;&#xFF0C;&#x7528;&#x4E8E;&#x63CF;&#x8FF0;&#x9879;&#x76EE;&#x7684;&#x57FA;&#x672C;&#x4FE1;&#x606F;&#x548C;&#x7ED3;&#x6784;&#x3002;</p>
<pre><code class="lang-yaml"><span class="hljs-comment"># &#x9879;&#x76EE;&#x540D;&#x79F0;</span>
<span class="hljs-attr">project:</span> myproject
<span class="hljs-comment"># &#x9879;&#x76EE;&#x63CF;&#x8FF0;</span>
<span class="hljs-attr">description:</span> This project uses nirvana as API framework
<span class="hljs-comment"># &#x670D;&#x52A1;&#x4F7F;&#x7528;&#x7684;&#x534F;&#x8BAE;&#xFF0C;&#x53EA;&#x80FD;&#x586B;&#x5199; http &#x548C; https</span>
<span class="hljs-attr">schemes:</span>
<span class="hljs-bullet">-</span> http
<span class="hljs-comment"># &#x8BBF;&#x95EE; IP &#x6216;&#x57DF;&#x540D;&#xFF0C;&#x53EF;&#x4EE5;&#x6709;&#x591A;&#x4E2A;</span>
<span class="hljs-attr">hosts:</span>
<span class="hljs-attr">- localhost:</span><span class="hljs-number">8080</span>
<span class="hljs-comment"># &#x9879;&#x76EE;&#x8D1F;&#x8D23;&#x4EBA;</span>
<span class="hljs-attr">contacts:</span>
<span class="hljs-attr">- name:</span> nobody
<span class="hljs-attr">  email:</span> nobody@nobody.io
<span class="hljs-attr">  description:</span> Maintain this project
<span class="hljs-comment"># &#x9879;&#x76EE; API &#x7248;&#x672C;&#x4FE1;&#x606F;&#xFF0C;&#x7528;&#x4E8E;&#x533A;&#x5206;&#x4E0D;&#x540C;&#x7248;&#x672C;&#x7684; API</span>
<span class="hljs-comment"># &#x7528;&#x4E8E;&#x6587;&#x6863;&#x548C;&#x5BA2;&#x6237;&#x7AEF;&#x751F;&#x6210;</span>
<span class="hljs-attr">versions:</span>
  <span class="hljs-comment"># &#x7248;&#x672C;&#x540D;&#x79F0;</span>
<span class="hljs-attr">- name:</span> v1
  <span class="hljs-comment"># &#x7248;&#x672C;&#x63CF;&#x8FF0;</span>
<span class="hljs-attr">  description:</span> The v1 version is the first version of this project
  <span class="hljs-comment"># &#x7248;&#x672C;&#x89C4;&#x5219;</span>
<span class="hljs-attr">  rules:</span>
    <span class="hljs-comment"># &#x8DEF;&#x5F84;&#x524D;&#x7F00;&#xFF0C;&#x5339;&#x914D;&#x524D;&#x7F00;&#x4E3A; &quot;/apis/v1&quot; &#x7684; API</span>
<span class="hljs-attr">  - prefix:</span> /apis/v1
    <span class="hljs-comment"># &#x6B63;&#x5219;&#x8868;&#x8FBE;&#x5F0F;&#xFF0C;&#x7528;&#x4E8E;&#x5339;&#x914D;&#x8DEF;&#x5F84;</span>
    <span class="hljs-comment"># &#x5982;&#x679C;&#x8BBE;&#x7F6E;&#x4E86; prefix&#xFF0C;&#x90A3;&#x4E48; regexp &#x5B57;&#x6BB5;&#x65E0;&#x6548;</span>
<span class="hljs-attr">    regexp:</span> <span class="hljs-string">&quot;&quot;</span>
    <span class="hljs-comment"># &#x8FD9;&#x4E2A;&#x5B57;&#x6BB5;&#x4EC5;&#x7528;&#x4E8E;&#x5728;&#x751F;&#x6210;&#x6587;&#x6863;&#x548C;&#x5BA2;&#x6237;&#x7AEF;&#x7684;&#x65F6;&#x5019;&#xFF0C;&#x66FF;&#x6362;&#x5339;&#x914D;&#x7684; API &#x8DEF;&#x5F84;&#x3002;&#x4E3A;&#x7A7A;&#x65F6;&#x4E0D;&#x4F1A;&#x8FDB;&#x884C;&#x66FF;&#x6362;&#x3002;</span>
    <span class="hljs-comment"># &#x6BD4;&#x5982;&#x8BBE;&#x7F6E; replacement = &quot;/apis/myproject/v1&quot;</span>
    <span class="hljs-comment"># &#x90A3;&#x4E48; &quot;/apis/v1/someapi&quot; &#x4E3A;&#x88AB;&#x66FF;&#x6362;&#x4E3A; &quot;/apis/myproject/v1/someapi&quot;</span>
<span class="hljs-attr">    replacement:</span> <span class="hljs-string">&quot;&quot;</span>
</code></pre>
<p>&#x8FD9;&#x4E2A;&#x914D;&#x7F6E;&#x6587;&#x4EF6;&#x4E0D;&#x4F1A;&#x5F71;&#x54CD; Server &#x7684;&#x8FD0;&#x884C;&#xFF0C;&#x53EA;&#x7528;&#x4E8E;&#x63CF;&#x8FF0;&#x9879;&#x76EE;&#x7684;&#x4FE1;&#x606F;&#x4EE5;&#x53CA;&#x533A;&#x5206;&#x4E0D;&#x540C;&#x7248;&#x672C;&#x7684; API&#x3002;API &#x6587;&#x6863;&#x751F;&#x6210;&#x548C;&#x5BA2;&#x6237;&#x7AEF;&#x751F;&#x6210;&#x4F1A;&#x4F9D;&#x8D56;&#x8FD9;&#x4E2A;&#x914D;&#x7F6E;&#x6587;&#x4EF6;&#x8FDB;&#x884C; API &#x7248;&#x672C;&#x8BC6;&#x522B;&#x548C; API &#x8DEF;&#x5F84;&#x66FF;&#x6362;&#xFF0C;&#x56E0;&#x6B64;&#x9700;&#x8981;&#x6B63;&#x786E;&#x8BBE;&#x7F6E;&#x7248;&#x672C;&#x89C4;&#x5219;&#x3002;</p>

                                
                                </section>
                            
    </div>
    <div class="search-results">
        <div class="has-results">
            
            <h1 class="search-results-title"><span class='search-results-count'></span> results matching "<span class='search-query'></span>"</h1>
            <ul class="search-results-list"></ul>
            
        </div>
        <div class="no-results">
            
            <h1 class="search-results-title">No results matching "<span class='search-query'></span>"</h1>
            
        </div>
    </div>
</div>

                        </div>
                    </div>
                
            </div>

            
                
                
                <a href="api.html" class="navigation navigation-next navigation-unique" aria-label="Next page: API">
                    <i class="fa fa-angle-right"></i>
                </a>
                
            
        
    </div>

    <script>
        var gitbook = gitbook || [];
        gitbook.push(function() {
            gitbook.page.hasChanged({"page":{"title":"项目结构和初始化","level":"1.2.1","depth":2,"next":{"title":"API","level":"1.2.2","depth":2,"path":"guides/api.md","ref":"guides/api.md","articles":[]},"previous":{"title":"快速入门","level":"1.2","depth":1,"ref":"","articles":[{"title":"项目结构和初始化","level":"1.2.1","depth":2,"path":"guides/project.md","ref":"guides/project.md","articles":[]},{"title":"API","level":"1.2.2","depth":2,"path":"guides/api.md","ref":"guides/api.md","articles":[]},{"title":"生成 API 文档","level":"1.2.3","depth":2,"path":"guides/doc.md","ref":"guides/doc.md","articles":[]},{"title":"生成客户端","level":"1.2.4","depth":2,"path":"guides/client.md","ref":"guides/client.md","articles":[]}]},"dir":"ltr"},"config":{"plugins":[],"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"pluginsConfig":{"highlight":{},"search":{},"lunr":{"maxIndexSize":1000000,"ignoreSpecialCharacters":false},"sharing":{"facebook":true,"twitter":true,"google":false,"weibo":false,"instapaper":false,"vk":false,"all":["facebook","google","twitter","weibo","instapaper"]},"fontsettings":{"theme":"white","family":"sans","size":2},"theme-default":{"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"showLevel":false}},"theme":"default","pdf":{"pageNumbers":true,"fontSize":12,"fontFamily":"Arial","paperSize":"a4","chapterMark":"pagebreak","pageBreaksBefore":"/","margin":{"right":62,"left":62,"top":56,"bottom":56}},"structure":{"langs":"LANGS.md","readme":"README.md","glossary":"GLOSSARY.md","summary":"SUMMARY.md"},"variables":{},"language":"zh-hans","gitbook":"*"},"file":{"path":"guides/project.md","mtime":"2020-09-23T08:26:07.589Z","type":"markdown"},"gitbook":{"version":"3.2.3","time":"2020-10-20T10:33:16.586Z"},"basePath":"..","book":{"language":"zh-hans"}});
        });
    </script>
</div>

        
    <script src="../../gitbook/gitbook.js"></script>
    <script src="../../gitbook/theme.js"></script>
    
        
        <script src="../../gitbook/gitbook-plugin-search/search-engine.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-search/search.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-lunr/lunr.min.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-lunr/search-lunr.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-sharing/buttons.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-fontsettings/fontsettings.js"></script>
        
    

    </body>
</html>

